package com.appbee.core.client.util;

import java.util.HashMap;

public class PathIndex<T>
{
	private final HashMap<String, T> index = new HashMap<String, T>();

	public void add(String path, T value)
	{
		index.put(path, value);
	}

	public T get(String path)
	{
		String subPath = path;
		T item = index.get(subPath);
		while (item == null)
		{
			int i = subPath.lastIndexOf("_");
			if (i < 1)
				return null;

			subPath = subPath.substring(0, i);
			item = index.get(subPath);
		}
		return item;
	}

	public void remove(String path)
	{
		index.remove(path);
	}
}
